drop table documentoborrado;

CREATE TABLE SIGIN.documentoborrado
(
  iddocumentoborrado  NUMBER                    NOT NULL,
  tipo                CHAR(1)                   NOT NULL,
  idpersona           NUMBER                    NOT NULL,
  fechahora           DATE                      NOT NULL,
  idelemento          NUMBER                    NOT NULL,
  nombre              VARCHAR2(255)             NOT NULL,
  datobusqueda        VARCHAR2(4000)            NOT NULL,
  datoinsert		  VARCHAR2(4000)			NOT NULL
)

LOGGING 
NOCACHE
NOPARALLEL;


ALTER TABLE SIGIN.documentoborrado ADD (
  CONSTRAINT PK_documentoborrado
 PRIMARY KEY
 (iddocumentoborrado));

ALTER TABLE SIGIN.documentoborrado ADD (
  CONSTRAINT FK_documentoborrado_persona 
 FOREIGN KEY (idpersona) 
 REFERENCES SIGIN.PERSONAS (idpersona));

CREATE SEQUENCE SIGIN.DOCUMENTOBORRADO_SEQ
START WITH 1
INCREMENT BY 1
MINVALUE 0
NOCACHE 
NOCYCLE 
NOORDER;

CREATE OR REPLACE TRIGGER SET_DOCUMENTOBORRADO_ID
   BEFORE INSERT
   ON DOCUMENTOBORRADO
   REFERENCING NEW AS NEW OLD AS OLD
   FOR EACH ROW
DECLARE
   tmpvar   NUMBER;
BEGIN
   tmpvar := 0;

   SELECT DOCUMENTOBORRADO_SEQ.NEXTVAL
     INTO tmpvar
     FROM DUAL;

   :NEW.iddocumentoborrado := tmpvar;
END SET_DOCUMENTOBORRADO_ID;